package com.xm_jd.controller.ht;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xm_jd.model.dao.Ht_ShoopListDao;
import com.xm_jd.model.entitys.Pages;
import com.xm_jd.model.entitys.ShoopandPVO;
import com.xm_jd.utils.BaseServlet;


@WebServlet("/admin-index")
public class AdminIndexServlet extends BaseServlet{
	
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		String lb1 = req.getParameter("lb");
		
		int lb;
		String leib=null;
		//类别编号
		if(lb1!=null && !lb1.equals("")){
		List<ShoopandPVO> lb2= new Ht_ShoopListDao().leiname(lb1);
		lb=	lb2.get(0).getLeibie_id();
		leib = Integer.toString(lb);
		}
		
		int pingp;
		String pingpai1=null;
		String pp = req.getParameter("pp");
		
		//品牌编号
		if(pp!=null && !pp.equals("")){
		List<ShoopandPVO> pp2= new Ht_ShoopListDao().pingname(pp);
			pingp= pp2.get(0).getPingpai_id();
			pingpai1=Integer.toString(pingp);
		}	
		
		
		String g1 = req.getParameter("g1");
		if(g1!=null && !"".equals(g1)){
			if(g1.equals("上架")){
				g1="1";
			}else if(g1.equals("下架")){
				g1="2";
			}else if(g1.equals("全部")){
				g1=null;
			}
		}
		
		/*String g2 = req.getParameter("g2");*/
		//获得当前页码
				String current = req.getParameter("currentpage");
				Integer currentpage = current==null ? 1:Integer.parseInt(current);
				//定页大小
				int pagesize = 4;
				//总记录数
				int total = new Ht_ShoopListDao().getTotalNews();
				//根据当前页码和页大小查询记录
				List<ShoopandPVO> list = new Ht_ShoopListDao().getNewsList(leib,pingpai1, g1,currentpage, pagesize);
			
				//封装
				Pages<ShoopandPVO> pages = new Pages<>(currentpage,pagesize,total,list);
				//存入作用域
				req.setAttribute("ggg", pages);
		
		
		List<ShoopandPVO> leibie = new Ht_ShoopListDao().leibie();
		List<ShoopandPVO> pingpai = new Ht_ShoopListDao().pingpai();
//		List<ShoopandPVO> goodlist = new Ht_ShoopListDao().goodlistp(leib,pingpai1, g1);
	
//		req.setAttribute("goodlist",goodlist);	
		req.setAttribute("lb", leibie);
		req.setAttribute("pp", pingpai);
		this.forward("admin-index");
	}
	
}
